# !usr/bin/env python
# -*- coding:utf-8 _*-
"""
@Author:张广勤
@Web site: https://www.tunan.wang
@Github:www.github.com
 
@File:Yi2_0.py
@Time:2024/8/7 16:01

@Motto:不积跬步无以至千里，不积小流无以成江海！
"""

import random

def coin_toss_to_trigram(toss):
    """
    将三枚铜钱的结果转换为卦象（少阳、老阳、少阴、老阴）
    :param toss: 投掷结果列表，包含三个'H'或'T'
    :return: 卦象字符串
    """
    counts = toss.count('H'), toss.count('T')
    if counts == (3, 0):
        return "老阳 ——"
    elif counts == (2, 1):
        return "少阴 --"
    elif counts == (1, 2):
        return "少阳 ——"
    else:
        return "老阴 --"

# 初始化记录每次投掷结果的列表
results = []

# 投掷六次
for _ in range(6):
    # 初始化单次投掷的结果列表
    single_throw = ['H' if random.random() < 0.5 else 'T' for _ in range(3)]
    # 转换为卦象
    trigram = coin_toss_to_trigram(single_throw)
    # 记录投掷结果和卦象
    results.append((single_throw, trigram))

# 打印每次投掷的结果和卦象
for i, (throw, trigram) in enumerate(results, 1):
    print(f"投掷{i}: {' '.join(throw)} -> {trigram}")

# 如果需要，可以计算并打印总的正面和背面次数
total_heads = sum(throw.count('H') for throw, _ in results)
total_tails = sum(throw.count('T') for throw, _ in results)

print(f"总共正面次数: {total_heads}")
print(f"总共背面次数: {total_tails}")